package cn.xiaobai;

import cn.xiaobai.listener.RedisClientListener;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author yangdaji
 * @Date 2023/11/2
 * @PackageName cn.xiaobai
 * @ClassName SubscriberDemo
 */
@Component
public class SubscriberDemo {

    @Autowired
    private RedisClientListener redisClientListener;


    @PostConstruct
    public void run() throws Exception {

        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(2);
        String top1 = "test";
        String top2 = "test2";
        scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> {
            redisClientListener.publish(top1, "redis 数据推送, 频道: " + top1);
            redisClientListener.publish(top2, "redis 数据推送, 频道: " + top2);
        }, 0, 1, TimeUnit.SECONDS);


    }
}
